package com.example.webapp.service;

import com.example.webapp.entity.RequestGroup;
import com.example.webapp.repository.RequestGroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RequestGroupService {
    @Autowired
    private RequestGroupRepository requestGroupRepository;
    
    public List<RequestGroup> getGroupsByProjectId(Long projectId) {
        return requestGroupRepository.findByProjectId(projectId);
    }
    
    public RequestGroup createGroup(String name, Long projectId) {
        RequestGroup group = new RequestGroup();
        group.setName(name);
        group.setProjectId(projectId);
        return requestGroupRepository.save(group);
    }
    
    public RequestGroup updateGroup(Long id, String name, String description) {
        RequestGroup group = requestGroupRepository.findById(id)
            .orElseThrow(() -> new RuntimeException("Group not found"));
        
        group.setName(name);
        group.setDescription(description);
        
        return requestGroupRepository.save(group);
    }
    
    public void deleteGroup(Long id) {
        requestGroupRepository.deleteById(id);
    }
} 